function [trial] = run_trial(task,stimulus,frame,varargin)
% run_trial - run one trial of a given task
trial = trial_constructor;
if nargin<3
    global EXPE;
    w=EXPE.frame.ptr;
    rect=EXPE.frame.rect;
elseif isnumeric(frame)
    w=frame;
    rect = Screen('Rect',w);
else
    w=frame.ptr;
    rect=frame.rect;
end
trial.stim = stimulus;
switch task
    case 'baldassi'        
        [trial.resp,trial.rt,trial.acc,trial.info.i_target,trial.info.t] = baldassi(w,rect,stimulus.angle,stimulus.n);

    case 'sternbergfaces'
		[trial.resp,trial.rt,trial.info.t] = sternbergfaces(stimulus.images,w,rect,stimulus.delay);
        trial.acc = trial.resp == (stimulus.corr>0);
        %acc= stimType(1,:)==resp;
        %i_target=stimType(2,:)

    case 'emotion' 
        [trial.resp,trial.rt,trial.info.t] = block_emotion(w,rect,stimulus.image,stimulus.noise);
        trial.acc= trial.resp==stimulus.corr;
end

